//
//  MineHeadTableViewCell.m
//  ForestPack
//
//  Created by 郑洲 on 2018/7/3.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "MineHeadTableViewCell.h"

@interface MineHeadTableViewCell ()

@property (nonatomic, strong) UIImageView *bgView;
@property (nonatomic, strong) UIImageView *headImage;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *infoLabel;

@end

@implementation MineHeadTableViewCell

+ (MineHeadTableViewCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"MineHeadTableViewCell";
    MineHeadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[MineHeadTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    self.bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(193) + STATUS_BAR_HEIGHT)];
    self.bgView.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:self.bgView];
    
    UIView *allBg = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(18), ScreenX375(147) + STATUS_BAR_HEIGHT, (SCREEN_WIDTH - ScreenX375(36)), ScreenX375(220))];
    allBg.backgroundColor = [UIColor whiteColor];
    allBg.layer.cornerRadius = ScreenX375(8);
    allBg.layer.shadowColor = RGBACOLOR(0, 0, 0, 0.06).CGColor;
    allBg.layer.shadowOpacity = 1;
    allBg.layer.shadowOffset = CGSizeMake(0, 3);
    allBg.layer.shadowRadius = 15;
    [self addSubview:allBg];
    
    self.headImage = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - ScreenX375(96)) / 2, ScreenX375(99) + STATUS_BAR_HEIGHT, ScreenX375(96), ScreenX375(96))];
    self.headImage.layer.cornerRadius = ScreenX375(57);
    self.headImage.image = [UIImage imageNamed:@"头像1"];
    self.headImage.layer.cornerRadius = ScreenX375(48);
    self.headImage.clipsToBounds = YES;
    self.headImage.layer.borderWidth = ScreenX375(4);
    self.headImage.layer.borderColor = REXADECIMALCOLOR(@"#ffffff").CGColor;
    [self addSubview:self.headImage];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, ScreenX375(60), SCREEN_WIDTH - ScreenX375(36), ScreenX375(24))];
    self.nameLabel.textColor = REXADECIMALCOLOR(@"#222222");
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    self.nameLabel.font = KBlodfont(16);
    [allBg addSubview:self.nameLabel];
    
    self.infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, ScreenX375(84), SCREEN_WIDTH - ScreenX375(36), ScreenX375(17))];
    self.infoLabel.textColor = REXADECIMALCOLOR(@"#9b9b9b");
    self.infoLabel.font = Kfont(12);
    self.infoLabel.textAlignment = NSTextAlignmentCenter;
    [allBg addSubview:self.infoLabel];
    
    NSArray *nameArr = @[@"发布",@"粉丝",@"排名",@"财富",@"喜欢",@"评论",@"关注",@"分享"];
    NSArray *contentArr = @[@"16",@"20",@"6",@"126",@"8",@"0",@"4",@"22"];
    CGFloat width = (SCREEN_WIDTH - ScreenX375(36)) / 4;
    for (int i = 0; i < nameArr.count; i++) {
        UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(i % 4 * width, ScreenX375(132) + i / 4 * ScreenX375(49), width, ScreenX375(18))];
        nameLabel.textColor = REXADECIMALCOLOR(@"#000000");
        nameLabel.text = nameArr[i];
        nameLabel.textAlignment = NSTextAlignmentCenter;
        nameLabel.font = Kfont(13);
        [allBg addSubview:nameLabel];
        
        UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(i % 4 * width, ScreenX375(115) + i / 4 * ScreenX375(49), width, ScreenX375(18))];
        contentLabel.textColor = REXADECIMALCOLOR(@"#4a4a4a");
        contentLabel.text = contentArr[i];
        contentLabel.textAlignment = NSTextAlignmentCenter;
        contentLabel.font = Kfont(13);
        contentLabel.tag = 200 + i;
        [allBg addSubview:contentLabel];
        
        UIButton *classBtn = [[UIButton alloc] initWithFrame:CGRectMake(i % 4 * width, ScreenX375(115)+ i / 4 * ScreenX375(49), width, ScreenX375(60))];
        classBtn.backgroundColor = [UIColor clearColor];
        classBtn.tag = 100 + i;
        [classBtn addTarget:self action:@selector(classClick:) forControlEvents:UIControlEventTouchUpInside];
        [allBg addSubview:classBtn];
    }
}

- (void)setDictionary:(NSDictionary *)dictionary {
    _dictionary = dictionary;
    
    self.nameLabel.text = dictionary[@"userInfo"][@"nickName"];
    NSArray *contentArr = @[[NSString stringWithFormat:@"%@",dictionary[@"proNum"]],
                            [NSString stringWithFormat:@"%@",dictionary[@"fensNum"]],
                            [NSString stringWithFormat:@"%@",dictionary[@"no"]],
                            [NSString stringWithFormat:@"%@",dictionary[@"userInfo"][@"coin"]],
                            [NSString stringWithFormat:@"%@",dictionary[@"likeNum"]],
                            [NSString stringWithFormat:@"%@",dictionary[@"appraiseNum"]],
                            [NSString stringWithFormat:@"%@",dictionary[@"concernedNum"]],
                            [NSString stringWithFormat:@"%@",dictionary[@"shareNum"]]];
    for (int i = 0; i < contentArr.count; i++) {
        UILabel *label = [self viewWithTag:200 + i];
        label.text = contentArr[i];
    }
    if ([dictionary[@"userInfo"][@"background"] class] != [NSNull class]) {
        [self.bgView sd_setImageWithURL:[NSURL URLWithString:dictionary[@"userInfo"][@"background"]] placeholderImage:nil options:SDWebImageRetryFailed];
    }else {
        self.bgView.image = ImageWithName(@"14");
    }
    if ([dictionary[@"userInfo"][@"pic"] class] != [NSNull class]) {
        [self.headImage sd_setImageWithURL:[NSURL URLWithString:dictionary[@"userInfo"][@"pic"]] placeholderImage:nil options:SDWebImageRetryFailed];
    }
    if ([dictionary[@"userInfo"][@"intro"] class] != [NSNull class]) {
        self.infoLabel.text = dictionary[@"userInfo"][@"intro"];
    }
}

- (void)classClick:(UIButton *)btn{
    if (_indexClick) {
        _indexClick(btn.tag - 100);
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
